public class Teat5 {
    public static void main(String[] args) {
        int []array = {2,2,2,2,2,2,2,5,5,5,566,7,8};
        System.out.println(fun(array));
    }
    public static int fun(int []array) {
        int [] []count = new int[array.length][1];
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if((array[i]^array[j]) == 0) {
                    count[i][0]++;
                }
            }
        }
        int [][]count1 = count;
        for (int i = 0; i < count1.length-1; i++) {
            if(count1[i][0]>count1[i+1][0]) {
                int tmp = count1[i][0];
                count1[i][0] = count1[i+1][0];
                count1[i+1][0] = tmp;
            }
        }
        int iMax = 0;
        for (int i = 0; i < count.length; i++) {
            if(count[i][0] == count1[count1.length-1][0]) {
                iMax = i;
            }
        }
        return array[iMax];
    }
}
